<template>
	<view class="container">
		<view class="list-cell b-b m-t" @click="navTo('/pages/user/userinfo')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">个人资料</text>
			<text class="cell-tip">{{userInfo.nickname}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b m-t" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">手机号</text>
			<text class="cell-tip">{{userInfo.mobile}}</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('/pages/user/changepwd')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">修改登录密码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('/pages/user/changepaypwd')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">修改支付密码</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b" @click="navTo('/pages/user/findpaypwd')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">忘记支付密码？</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		
		<view
			class="list-cell b-b m-t"
			@click="navTo('/pages/user/verified')"
			hover-class="cell-hover"
			:hover-stay-time="50"
			v-if="userInfo.identitystatus == 0 || userInfo.identitystatus == undefined"
		>
			<text class="cell-tit">实名认证</text>
			<text class="cell-tip">点击实名认证</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell b-b m-t" v-else @click="navTo('/pages/user/verified_info')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">实名认证</text>
			<text class="cell-tip">已实名（{{userInfo.truename}}）</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		
		<view class="list-cell b-b" @click="navTo('/pages/user/about')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">关于我们</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell">
			<text class="cell-tit">检查更新</text>
			<text class="cell-tip">当前版本 1.0.1</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<view class="list-cell log-out-btn" @click="toLogout"><text class="cell-tit">退出登录</text></view>
	</view>
</template>

<script>
import { mapMutations, mapState } from 'vuex';

export default {
	data() {
		return {
			token: '',
			userInfo: {}
		};
	},
	onLoad() {
		
	},
	onShow() {
		this.token = this.$api.get('token');
		if (!this.token) {
			uni.navigateTo({
				url: '/pages/public/login'
			});
			return;
		}
		//获取用户信息
		this.getmedate();
	},
	computed: {
		//对全局变量进行监控
		...mapState(['hasLogin'])
	},
	methods: {
		//对全局方法进行监控
		...mapMutations(['logout']),

		/**
		 * 统一跳转接口,拦截未登录路由
		 * navigator标签现在默认没有转场动画，所以用view
		 */
		navTo(url) {
			if (!this.token) {
				url = '/pages/public/login';
			}
			uni.navigateTo({
				url
			});
		},

		//退出登录
		toLogout() {
			uni.showModal({
				content: '确定要退出登录么',
				success: e => {
					if (e.confirm) {
						this.logout();
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/public/login'
							});
						}, 200);
					}
				}
			});
		},

		//获取用户信息
		async getmedate() {
			const param_userinfo = {
				token: this.token
			};
			await this.$http.request('User', 'userinfo', 'GET', param_userinfo, res => {
				if (res.status == 1) {
					if (res.data.error == 0) {
						this.userInfo = res.data.data;
					}
				}
			});
		},
		
		
	}
};
</script>

<style lang="scss">
page {
	background: $page-color-base;
}
.list-cell {
	display: flex;
	align-items: baseline;
	padding: 20upx $page-row-spacing;
	line-height: 60upx;
	position: relative;
	background: #fff;
	justify-content: center;

	&.log-out-btn {
		margin-top: 40upx;
		.cell-tit {
			color: $uni-color-primary;
			text-align: center;
			margin-right: 0;
		}
	}
	&.cell-hover {
		background: #fafafa;
	}
	&.b-b:after {
		left: 30upx;
	}
	&.m-t {
		margin-top: 16upx;
	}
	.cell-more {
		align-self: baseline;
		font-size: $font-lg;
		color: $font-color-light;
		margin-left: 10upx;
	}
	.cell-tit {
		flex: 1;
		font-size: $font-base + 2upx;
		color: $font-color-dark;
		margin-right: 10upx;
	}
	.cell-tip {
		font-size: $font-base;
		color: $font-color-light;
	}
	switch {
		transform: translateX(16upx) scale(0.84);
	}
}
</style>
